package com.xyzwps.server.paimon.ui.mvc

import com.xyzwps.server.paimon.app.dto.RegisterInput
import com.xyzwps.server.paimon.app.dto.RegisterSendVcodeInput
import com.xyzwps.server.paimon.app.RegisterAppService
import com.xyzwps.server.paimon.ui.HttpResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@Tag(name = "User Register")
@RestController
@RequestMapping(Apis.BASE + "/register")
class RegisterController(private val registerAppService: RegisterAppService) {

    @Operation(summary = "User register")
    @PostMapping
    fun register(@RequestBody @Valid input: RegisterInput): HttpResponse<Unit> {
        registerAppService.register(input)
        return HttpResponse.ofUnit() // TODO: 观察这东西的行为
    }

    @Operation(summary = "Send register vcode", description = "This api would return a dkey.")
    @PostMapping("/send-vcode")
    fun sendRegisterVcode(@RequestBody @Valid input: RegisterSendVcodeInput): HttpResponse<String> {
        return HttpResponse(registerAppService.sendRegisterVcode(input))
    }
}
